This invention relates to a method of controlling a cache memory. More particularly, the invention relates to a cache memory control method in an apparatus having a first cache memory in which stored data vanishes owing to cut-off of power and a second cache memory in which stored data is saved even if power is cut off.
In image output devices such as printers and display units, an increase in the processing speed of the host apparatus (computer) has been accompanied by the need for high-speed image output and for the output of fonts of various types and sizes. Consequently, these image output devices have a first cache memory (RAM cache) comprising a RAM accessible at high speed, a second cache memory (disk cache) composed of part of the storage area of a disk-shaped storage medium and a cache memory controller, and they use these elements to raise the speed at which character-image data is produced in order to provide higher printing and display speeds. In image output devices of this kind, the cache memory controller preserves used new data (character-image data) in the RAM cache if the RAM cache is not full. If the RAM cache is full, the cache memory controller saves part of the character-image data that has been saved in the RAM cache in the disk cache and then saves the above-mentioned new character-image data in the RAM cache. When prescribed character-image data is necessary, the cache memory controller searches the RAM cache and then the disk cache if the data is not present in the RAM cache. The prescribed processing is executed using the character-image data retrieved by the search. If the data cannot be found, character-image data is produced anew and saved in the RAM cache.
In a printer, for example, outline-font data is stored beforehand in correlation with characters (inclusive of symbols). When a character code and its magnification (font size) have been designated, the outline-font data corresponding to the character code is multiplied by the designated magnification and the outline of the character having the desired size is printed and painted to produce the character-image data. However, producing character-image data from outline-font data requires considerable time. Accordingly, once character-image data has been created in a printing device, the data is preserved in the RAM cache and disk cache beforehand. When a prescribed font code has been entered, the RAM cache is searched and then the disk cache if the code is not found in the RAM cache. The prescribed processing such as printing is performed using the character-image data retrieved by the search. In a case where the character-image data cannot be found, character-image data is produced and printed using outline-font data corresponding to the font code and this character-image data is saved in the RAM cache and disk cache. It should be noted that outline-font data is font data in which the outline of a character is expressed in the form of vectors. The reason for using the outline-font data is that this data can be stored with a memory capacity much smaller than that needed for character-image data.
FIGS. 1 and 2 are diagrams for describing cache memory control in a conventional printer. Shown in FIG. 1 are a control unit 1 for controlling the overall printer, a printer main body (mechanical mechanisms, the printer head, mechanical controller, head driver, etc.) 2, an operator's panel 3 having a display unit and various operating keys, and a hard disk 4.
The control unit 1 is provided with a controller 1a constituted by a microcomputer and a cache memory (hereinafter referred to as a RAM cache) 1b constituted by a RAM for storing character-image data once this data has been created. The hard disk 4 is provided with an outline-font data storage area 4a for storing outline-font data in correlation with character codes, a disk-cache storage area (hereinafter referred to simply as a disk cache) 4b for storing character-image data transferred thereto owing to overflow from the RAM cache, and other storage areas such as a storage area which stores system programs and the like for printer control.
Upon receiving data (a character code string) or a command from the host apparatus, the control unit 1 performs analysis to determine if what has been received is a character code. In the case of the character code, the control unit searches the RAM cache 1b and then the disk cache 4b if the code is not present in the RAM cache 1b. The character-image data retrieved by the search is fed into the head driver of the printer main body 2 to perform printing. If the character code cannot be found, the control unit 1 uses outline-font data corresponding to the character code to produce character-image data anew and print the data. The control unit 1 preserves this newly created character-image data in the RAM cache 1b. If the RAM cache is full in this case, some of the data that has been saved in the RAM cache is transferred to the disk cache 4b to produce a blank space in the RAM cache, after which the new character-image data is saved in the RAM cache.
If the control unit 1 receives a line-feed command, page-eject command or the like from the host apparatus or operator's panel 3, the control unit 1 sends the line-feed or page-eject command to the mechanical control portion of the printer main body 2, thereby causing the mechanical control portion to control a line-feed mechanism or page-eject mechanism so that these operations are carried out.
The size of the RAM cache 1b is limited and is capable of storing only 100 to 200 items of character-image data, by way of example. For this reason, a least recently used (LRU) algorithm is used to assign the highest order of priority to the character-image data used last, and the character-image data is stored in the RAM cache 1b with the order of priority being assigned in the order in which the data was used. More specifically, if the RAM cache 1b is not full, newly created character-image data is saved in the RAM cache 1b upon having the highest order of priority assigned to it, and the orders of priority of other items of character-image data already stored in the RAM cache are each lowered by one rank. If the RAM cache is full, on the other hand, character-image data having the lowest order of priority (i.e., least recently used character-image data) is transfer red from the RAM cache 1b to the disk cache 4b, whereby the data is saved, thereby producing space in the RAM cache 1b. Thereafter, newly created character-image data is saved in the RAM cache 1b upon having the highest order of priority assigned to it, and the orders of priority of other items of character-image data already stored in the RAM cache are each lowered by one rank.
The disk cache 4b, which is capable of storing on the order of 500 items of character-image data for example, saves transferred character-image data while the order of priority is assigned to this data in the same manner as performed by the RAM cache 1b. In other words, if the disk cache 4b is not full, character-image data transferred from the RAM cache 1b is preserved in the disk cache 4b upon having the highest order of priority assigned to it, and the orders of priority of other items of character-image data already stored in the disk cache are each lowered by one rank. If the disk cache 4b is full, on the other hand, character-image data having the lowest order of priority (i.e., least recently used character-image data) is discarded to make space, after which transferred character-image data is saved in the disk cache 4b upon having the highest order of priority assigned to it and the orders of priority of other items of character-image data already stored in the disk cache are each lowered by one rank.
If the power supply is cut off under these conditions, the data that has been stored in the RAM cache 1b vanishes. When the power is introduced, therefore, some of the character-image data that has been saved in the disk cache 4b is transferred to the RAM cache 1b, after which the above-described cache memory control is carried out.
FIG. 2 is an explanatory view of cache memory control according to the prior art. In order to simplify the description, this is for a case in which a maximum of four items of character-image data and a maximum of six items of character-image data are capable of being stored in the RAM cache 1b and disk cache 4b, respectively, with the order of priority of the data ascending from right to left. If the RAM cache and disk are full, as illustrated at (1) in FIG. 2, and new character-image data (data 0) is produced, first 1 the character-image data (data 10) having the lowest order of priority is discarded from the disk cache 4b to make space equivalent to one item of character-image data, then 2 the character-image data (data 4) having the lowest order of priority is transferred from the RAM cache 1b to the disk cache 4b in order to be saved (with the highest order of priority assigned being thereto), and finally 3 the new character-image data (data 0) is saved in the RAM cache 1b and has the highest order of priority assigned thereto. Thus, character-image data (data 0.about.data 9) is saved in the cache memories as shown at (2) in FIG. 1.
If the power supply is cut off under the conditions shown at (2), the data that has been stored in the RAM cache 1b vanishes. When power is re-introduced, the four items of character-image data (data 4.about.data 7) having the high orders of priority saved in the disk cache 4b are transferred to the RAM cache 1b to produce a space in the disk cache that is equivalent to the four transferred characters. As a result, character-image data (data 4.about.data 7) is saved in the RAM cache 1b and character-image data (data 8.about.data 9) is saved in the disk cache 4b, as illustrated at (3) in FIG. 2. The cache control described above is then carried out.
With the prior-art cache memory control described above, however, data having a high order of priority stored in the RAM cache vanishes when power is cut off. Consequently, this high-priority data cannot be recovered in the processing that follows the re-introduction of power, the hit rate declines and therefore a problem arises in terms of high-speed processing.
Other problems are also encountered in the conventional method of controlling cache memory.
Specifically, control of a cache memory (RAM cache and disk cache) is fixed within the apparatus. Consequently, use of a cache memory becomes effective in cases where the same character appears repeatedly a number of times.
1 However, when it is attempted to print out a kanji code table, for example, identical characters do not appear and therefore the character-image data of a character of interest is not obtained from the cache memory. This means that the character-image data of every character is created using outline-font data. In such cases, the operation of saving character-image data in the cache memory becomes meaningless. Accordingly, in the printout of characters all of which are different, as in the case of a kanji code table, printing speed (the speed at which character-image data is produced) declines by an amount equivalent to the number of superfluous saving operations required.
2 Further, when magnification of a character takes on a large value, the volume of character data also becomes large. As a consequence, loading the character-image data from the cache memory takes time and there are cases in which it is faster to generate the character-image data from outline-font data. In such cases, saving newly generated character-image data in the cache memory and loading the data are useless operations.
3 Furthermore, depending upon the type, certain characters almost never appear in ordinary text. Using a cache memory to save character-image data of characters almost never used, as is the case with the No. 2 Level characters of the JIS, is wasteful since it does nothing more than place a limit upon the storage area of the cache memory. Herein, the No.2 Level characters of the JIS are gathering of KANJI in Japanese which are not used ordinarily. And, the No.1 Level characters of the JIS are gathering of KANJI in Japanese which are used ordinarily.
Moreover, when a cache memory is filled with hardly used characters such as the No. 2 Level characters of the JIS and a character code composed of the frequently used No. 1 Level characters of the JIS is received, not only is the cache memory rendered substantially meaningless but data discarding processing by overflow must be executed as well.
The conventional cache memory control method has the following disadvantages as well:
In cache memory control, processing is executed for transferring data from the RAM cache of the control apparatus to the disk cache of the hard disk and writing the data in the disk cache. The processing executed by the control unit for writing the data (character-image data) in the hard disk is performed in the following manner: When a data transfer is required, the controller 1a (see FIG. 1) instructs, via a disk interface (not shown), that data of a prescribed length is to be written in the hard disk 4. A disk controller (not shown) writes the data in the hard disk 4 one block unit at a time (one block is composed of, say, 256 bytes), where the block units are the units of access, and attaches an ECC (error-checking code) to the end of each block. That is, as shown in FIG. 3, in a case where data is written in a physical sector PS, first a gap GP1, an ID and a gap GP2 are provided, after which a first block BL1 composed of the 256-byte data and the ECC is written in. This is followed by providing a gap GP3, then writing in a second block BL3 comprising 256-byte data and the ECC and finally providing a gap GP4 and a servozone SVZ.
A situation may arise in which the power supply is interrupted momentarily or cut off when character-image data of one character unit is in the process of being saved in the disk cache 4b from the RAM cache 1b. For example, this can occur when there is a power failure, when a power-supply switch is opened inadvertently or when someone trips over a power cord and pulls it out of its socket.
In such cases, the writing of one block cannot proceed owing to the loss of power and, as a result, the ECC is not attached to the end of the block. If the ECC fails to be attached, a read error will occur when the physical sector is read after the re-introduction of power and, depending upon the saving method, the data in the disk cache or the data in a management table will be destroyed. Nevertheless, measures to protect data and measures to protect the physical sector in the event of a momentary interruption in power or power outage during the writing in of data from an external storage device are not taken in the prior art. As a consequence, data is lost or a read error occurs when it is attempted to read the physical sector. Software must be reinstalled or a restoration operation must be performed.